<?php

require_once __DIR__ . '/includes/BasketbalFunctions.php';
$basketbalfunctions = new BasketbalFunctions();

$username = $_POST['username'];

$clicked_item = $_POST['name'];

$user_key = $basketbalfunctions->GetUserkeyFromUsername($username);

try{  
	 $connect = new PDO('mysql:host=localhost;dbname=basketbal','cas','cas');
	 $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	 $query = "INSERT INTO clicked_items (user_key, clicked_item) VALUES (:user_key, :clicked_item)";
	 $statement = $connect->prepare($query);
	 $sql_status = $statement->execute(
	  array(
	   ':user_key'  => $user_key,
	   ':clicked_item'  => $clicked_item
	  )
	 );
	 
	 $output = '';
	 if ($sql_status) {
	 	  $output = "clicked $clicked_item";
	 } else {
	 	$output = "Something Wrong";
	 }

} catch (PDOException $e) {
    
    $output = $e->getMessage();
}

 echo $output;

?>